/**
* Copyright (C) 2018-2020
* All rights reserved, Designed By www.yixiang.co
* 注意：
* 本软件为www.yixiang.co开发研制，未经购买不得使用
* 购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
* 一经发现盗用、分享等行为，将追究法律责任，后果自负
*/
package co.yixiang.mall.biz.mallsetting.service.impl;


import co.yixiang.common.core.utils.FileUtil;
import co.yixiang.common.mproot.common.service.impl.BaseServiceImpl;
import co.yixiang.common.mproot.common.utils.QueryHelpPlus;
import co.yixiang.common.mproot.domain.PageResult;
import co.yixiang.common.mproot.dozer.service.IGenerator;
import co.yixiang.mall.biz.mallsetting.mapper.TbBrokerageFreezeMapper;
import co.yixiang.mall.biz.mallsetting.service.TbBrokerageFreezeService;
import co.yixiang.mall.common.mallsetting.domain.TbBrokerageFreeze;
import co.yixiang.mall.common.mallsetting.dto.TbBrokerageFreezeDto;
import co.yixiang.mall.common.mallsetting.dto.TbBrokerageFreezeQueryCriteria;
import lombok.AllArgsConstructor;

import com.github.pagehelper.PageInfo;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.data.domain.Pageable;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
/**
* @author hupeng
* @date 2021-03-23
*/
@Service
@AllArgsConstructor
//@CacheConfig(cacheNames = "tbBrokerageFreeze")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class TbBrokerageFreezeServiceImpl extends BaseServiceImpl<TbBrokerageFreezeMapper, TbBrokerageFreeze> implements TbBrokerageFreezeService {

    private final IGenerator generator;

    @Override
    //@Cacheable
    public PageResult<TbBrokerageFreezeDto> queryAll(TbBrokerageFreezeQueryCriteria criteria, Pageable pageable) {
        getPage(pageable);
        PageInfo<TbBrokerageFreeze> page = new PageInfo<>(queryAll(criteria));
        return generator.convertPageInfo(page,TbBrokerageFreezeDto.class);
    }


    @Override
    //@Cacheable
    public List<TbBrokerageFreeze> queryAll(TbBrokerageFreezeQueryCriteria criteria){
        return baseMapper.selectList(QueryHelpPlus.getPredicate(TbBrokerageFreeze.class, criteria));
    }


    @Override
    public void download(List<TbBrokerageFreezeDto> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (TbBrokerageFreezeDto tbBrokerageFreeze : all) {
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("用户id", tbBrokerageFreeze.getUid());
            map.put("级差", tbBrokerageFreeze.getGradation());
            map.put("平级奖励", tbBrokerageFreeze.getLevelReward());
            map.put("冻结状态   0:不结算  1:可结算", tbBrokerageFreeze.getFrozenState());
            map.put("返佣金额", tbBrokerageFreeze.getBuyRebate());
            map.put("结算 0:未结算 1:已结算", tbBrokerageFreeze.getClearing());
            map.put("冻结积分", tbBrokerageFreeze.getFreezingIntegral());
            map.put("佣金结算时间", tbBrokerageFreeze.getSettleAccountsTime());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }
}
